<?php

class Empeval_FrontendController extends Zend_Controller_Action {

	const LOGIN_URL = '/empeval/logowanie';
	const LOGGED_URL = '/empeval/menu';
	
	public function init() {
		$this->_helper->viewRenderer->setNoRender(true);

		$compress = (bool) Zend_Registry::get('appConfig')->resources->layout->params->compress;
		$this->_helper->viewRenderer->setNoRender(true);
		$packages = new ViewPackages_PackageCreator('css', 'js/compressed', 'empeval');
		if ($compress) {
			$packages->init();
			$this->view->cssFiles = $packages->getCssFiles();
			$this->view->jsFiles = $packages->getJsFiles();
		} else {
			$this->view->cssFiles = $packages->getOriginalCssFiles();
			$this->view->jsFiles = $packages->getOriginalJsFiles();
		}
		$this->view->rootPath = strpos($this->getRequest()->getServer('REQUEST_URI'), $this->getRequest()->getModuleName()) ? '/' . $this->getRequest()->getModuleName() : '';
// 		if (!Empeval_Auth::getInstance()->isAuth() && self::LOGIN_URL != $this->getRequest()->getRequestUri()) {
// 			$this->_redirect(self::LOGIN_URL);
// 		}
	}

	public function indexAction() {
	}
	
	public function testAction() {
		$options = array(
				'host' => '10.48.248.11',
				'port' => '389',
				'accountDomainName' => 'skoda-auto.pl'
		);
		$ldap = new Zend_Ldap($options);
		$ldap->bind('position.manager', 'PM!@#skodagmi');
		$result = $ldap->search('(company=Volkswagen Group Polska)', $this->configData->usersDn);
		foreach ($result as $item) {
			Zend_Debug::dump($item);
		}
		die;
	}
	
// 	public function testAction() {
// 		$out = array();
// 		foreach (Empeval_Config::getInstance()->ldap->server as $server) {
// 			$out[] = $server->options->toArray();
// 		}
// 		Zend_Debug::dump($out);die;
// 		try {
// 			$options = array(
// 					array(
// 							'host' => '10.100.100.33',
// 							'port' => '389',
// 							'accountDomainName' => 'kulczyktradex.com.pl',
// 							'baseDn' => 'ou=users volkswagen group polska,ou=volkswagen group polska,dc=kulczyktradex,dc=com,dc=pl'
// 					),
// 					array(
// 							'host' => '10.48.248.102',
// 							'port' => '389',
// 							'accountDomainName' => 'skoda-auto.pl',
// 							'baseDn' => 'cn=users,dc=skoda-auto,dc=pl'
// 					)
// 			);
// 			$auth = Zend_Auth::getInstance();
// 			$adapter = new Zend_Auth_Adapter_Ldap($options, 'position.manager', '&*4hjkfdws86gfj');
// 			//$adapter = new Zend_Auth_Adapter_Ldap($options, 'position.manager', 'PM!@#skodagmi');
// 			//$adapter = new Zend_Auth_Adapter_Ldap($options, 'gmind.test@skoda-auto.pl', 'gim@123!45');
// 			$result = $auth->authenticate($adapter);
// 			Zend_Debug::dump($result);
// 		} catch (Exception $e) {
// 			var_dump($e->getMessage());
// 		}
// 		die;
// 	}

}